package com.wzt.gift.holder;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * UserContextInfo类持有者
 */
public class UserContextInfoHolder {
    private static LoginUserContextInfo contextInfo;

    //获取UserContextInfo
    public static LoginUserContextInfo  getUserContextInfo(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        String userContextInfoStr = (String) authentication.getPrincipal();
        LoginUserContextInfo userContextInfo
                = JSONObject.parseObject(userContextInfoStr, LoginUserContextInfo.class);
        return userContextInfo;
    }
}
